// Decompiled by GOOSIN CO,LTD Copyright 2010 Pavel Kouznetsov.
// home page: http://www.Goosin.net
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   file_draft_ok.java

package draft.design;

import include.nseer_cookie.*;
import include.nseer_db.nseer_db_backup1;
import include.operateDB.CdefineUpdate;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.StringTokenizer;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import javax.servlet.jsp.JspFactory;
import validata.ValidataNumber;
import validata.ValidataTag;

public class file_draft_ok extends HttpServlet
{

	public file_draft_ok()
	{
	}

	public void service(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException
	{
		HttpSession dbSession = request.getSession();
		JspFactory _jspxFactory = JspFactory.getDefaultFactory();
		javax.servlet.jsp.PageContext pageContext = _jspxFactory.getPageContext(this, request, response, "", true, 8192, true);
		javax.servlet.ServletContext dbApplication = dbSession.getServletContext();
		HttpSession session = request.getSession();
		nseer_db_backup1 design_db = new nseer_db_backup1(dbApplication);
		nseer_db_backup1 finance_db = new nseer_db_backup1(dbApplication);
		ValidataNumber validata = new ValidataNumber();
		ValidataTag vt = new ValidataTag();
		counter count = new counter(dbApplication);
		try
		{
			if (design_db.conn((String)dbSession.getAttribute("unit_db_name")) && finance_db.conn((String)dbSession.getAttribute("unit_db_name")))
			{
				String id = request.getParameter("id");
				String config_id = request.getParameter("config_id");
				String product_ID = request.getParameter("product_ID");
				String responsible_person_ID = "";
				String responsible_person_name = "";
				String fileKind_chain = request.getParameter("fileKind_chain");
				String chain_id = Divide1.getId(fileKind_chain);
				String chain_name = Divide1.getName(fileKind_chain);
				String oldKind_chain = request.getParameter("oldKind_chain");
				String oldChain_id = Divide1.getId(oldKind_chain);
				String product_name = request.getParameter("product_name");
				String factory_name = request.getParameter("factory_name");
				String type = request.getParameter("type");
				String product_class = request.getParameter("product_class");
				String product_nick = request.getParameter("product_nick");
				String twin_name = request.getParameter("twin_name");
				String twin_ID = request.getParameter("twin_ID");
				String personal_unit = request.getParameter("personal_unit");
				String personal_value = request.getParameter("personal_value");
				if (personal_value.equals("NaN"))
					personal_value = "0.00";
				personal_value = personal_value.replaceAll(",", "");
				String warranty = request.getParameter("warranty");
				String lifecycle = request.getParameter("lifecycle");
				String amount_unit = request.getParameter("amount_unit");
				String register = request.getParameter("register");
				String bodyc = new String(request.getParameter("provider_group").getBytes("UTF-8"), "UTF-8");
				String provider_group = exchange.toHtml(bodyc);
				String bodya = new String(request.getParameter("product_describe").getBytes("UTF-8"), "UTF-8");
				String product_describe = exchange.toHtml(bodya);
				String checker = request.getParameter("checker");
				String checker_ID = request.getParameter("checker_ID");
				String check_time = request.getParameter("check_time");
				String list_price2 = request.getParameter("list_price");
				StringTokenizer tokenTO4 = new StringTokenizer(list_price2, ",");
				String list_price;
				String list_price1;
				for (list_price = ""; tokenTO4.hasMoreTokens(); list_price = (new StringBuilder(String.valueOf(list_price))).append(list_price1).toString())
					list_price1 = tokenTO4.nextToken();

				String cost_price2 = request.getParameter("cost_price");
				StringTokenizer tokenTO5 = new StringTokenizer(cost_price2, ",");
				String cost_price;
				String cost_price1;
				for (cost_price = ""; tokenTO5.hasMoreTokens(); cost_price = (new StringBuilder(String.valueOf(cost_price))).append(cost_price1).toString())
					cost_price1 = tokenTO5.nextToken();

				int n = 0;
				if (!validata.validata(list_price) || Double.parseDouble(list_price) < 0.0D)
					n++;
				if (!validata.validata(cost_price) || Double.parseDouble(cost_price) < 0.0D)
					n++;
				if (vt.validata((String)dbSession.getAttribute("unit_db_name"), "design_file", "product_ID", product_ID, "check_tag").equals("5") || vt.validata((String)dbSession.getAttribute("unit_db_name"), "design_file", "product_ID", product_ID, "check_tag").equals("9"))
				{
					if (n == 0)
					{
						String sql2 = (new StringBuilder("select * from design_config_file_kind where chain_id='")).append(chain_id).append("'").toString();
						ResultSet rs2 = design_db.executeQuery(sql2);
						if (!chain_id.equals(""))
						{
							product_ID = request.getParameter("product_ID");
							if (product_ID == null || product_ID.equals(""))
								product_ID = NseerId.getId("design/file", (String)dbSession.getAttribute("unit_db_name"));
							try
							{
								String sql = (new StringBuilder("update design_file set chain_id='")).append(chain_id).append("',chain_name='").append(chain_name).append("',product_ID='").append(product_ID).append("',product_name='").append(product_name).append("',factory_name='").append(factory_name).append("',product_class='").append(product_class).append("',type='").append(type).append("',twin_name='").append(twin_name).append("',twin_ID='").append(twin_ID).append("',personal_unit='").append(personal_unit).append("',personal_value='").append(personal_value).append("',warranty='").append(warranty).append("',lifecycle='").append(lifecycle).append("',product_nick='").append(product_nick).append("',list_price='").append(list_price).append("',cost_price='").append(cost_price).append("',register='").append(register).append("',provider_group='").append(provider_group).append("',product_describe='").append(product_describe).append("',responsible_person_name='").append(responsible_person_name).append("',responsible_person_ID='").append(responsible_person_ID).append("',amount_unit='").append(amount_unit).append("',checker='").append(checker).append("',check_time='").append(check_time).append("' where product_ID='").append(product_ID).append("'").toString();
								design_db.executeUpdate(sql);
								CdefineUpdate CdefineUpdate = new CdefineUpdate();
								sql = CdefineUpdate.update("design_file", "product_ID", product_ID, request);
								design_db.executeUpdate(sql);
								if (!chain_id.equals("oldChain_id"))
								{
									sql = (new StringBuilder("select id from design_file where chain_id='")).append(oldChain_id).append("'").toString();
									ResultSet rs = design_db.executeQuery(sql);
									if (!rs.next())
									{
										sql = (new StringBuilder("update design_config_file_kind set delete_tag='0' where file_id='")).append(oldChain_id).append("'").toString();
										design_db.executeUpdate(sql);
									}
									sql = (new StringBuilder("update design_config_file_kind set delete_tag='1' where file_id='")).append(chain_id).append("'").toString();
									design_db.executeUpdate(sql);
								}
							}
							catch (Exception ex)
							{
								ex.printStackTrace();
							}
							response.sendRedirect((new StringBuilder("draft/design/file_choose_attachment.jsp?product_ID=")).append(product_ID).toString());
						} else
						{
							response.sendRedirect("draft/design/file_ok.jsp?finished_tag=1");
						}
					} else
					{
						response.sendRedirect("draft/design/file_ok.jsp?finished_tag=4");
					}
				} else
				{
					response.sendRedirect("draft/design/file_ok.jsp?finished_tag=2");
				}
				design_db.commit();
				finance_db.commit();
				design_db.close();
				finance_db.close();
			} else
			{
				response.sendRedirect("error_conn.htm");
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
